package com.gcl.rabbitmq;

import com.gcl.rabbitmq.utils.RabbtMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {


    public static final String EXCHANGE_NAME = "direct";


    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbtMQUtils.getChannel();

        // 声明直接交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        // 传递消息

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String msg = scanner.next();
//            channel.basicPublish(EXCHANGE_NAME, "error", null, msg.getBytes(StandardCharsets.UTF_8));
            channel.basicPublish(EXCHANGE_NAME, "info", null, msg.getBytes(StandardCharsets.UTF_8));
//            channel.basicPublish(EXCHANGE_NAME, "waring", null, msg.getBytes(StandardCharsets.UTF_8));
        }



    }



}
